import axios from '../../http/http'
/*import axios from 'axios'*/
import * as api from '../../http/api'
const state = {
    xhpData:[]//当前页
}
//actions异步改变 store
const actions = {
    //页面加载渲染消耗品
    getxhpData({commit},data){
        return axios({
            url:api.cb_getxhp,
            method: 'post',
            params:data,
            transformRequest:[function () {
                return JSON.stringify(data)
            }],
            headers:{
                'Content-Type':'application/json;'
            },
        }).then(res => {
            /*console.log(res)
            console.log(123);*/
            commit('addData',res.data.info)
            /* console.log(res.data.list)*/
            //拿到数据
            return res.data.info

        })



    },
    //修改的时候
    updata({commit},data){

        axios({
            url: api.cb_updatexhp,
            method: 'post',
            params: data,
            transformRequest:[function () {
                return JSON.stringify(data)
            }],
            headers:{
                'Content-Type':'application/json;'
            },
        }).then(res => {
          /*  console.log(88888)
            console.log(res)*/
            /*commit('updata',res.config.params)*/
            //return res.config.params
        })
    },
    //添加消耗品的时候
    addxhp({commit},data){

        axios({
            url: api.cb_addxhp,
            method: 'post',
            params: data,
            transformRequest:[function () {
                return JSON.stringify(data)
            }],
            headers:{
                'Content-Type':'application/json;'
            },
        }).then(res => {
        /*   /!* console.log(123456)
            console.log(res)
            console.log(res.config.params)*!/
            commit('xhpadd',res.config.params)
            //return res.config.params*/
       /* console.log('添加成功')*/
        })
    },
    //删除消耗品的时候
    removexhp({commit},data){
        /*console.log(data)*/
        axios({
            url: api.cb_removexhp,
            method: 'get',
            params: data,
        }).then(res => {
            /*console.log(res)
            console.log('删除成功')*/
        })
    },
    //进货时
    jinh({commit},data){
      /*  console.log(data)*/
        axios({
            url: api.cb_jin,
            method: 'post',
            params: data,
            transformRequest:[function () {
                return JSON.stringify(data)
            }],
            headers:{
                'Content-Type':'application/json;'
            },
        }).then(res => {
        /*    console.log(res)
            console.log('进货成功')*/
        })
    },

    //出货
    chuh({commit},data){
       /* console.log(data)*/
        axios({
            url: api.cb_chu,
            method: 'post',
            params: data,
            transformRequest:[function () {
                return JSON.stringify(data)
            }],
            headers:{
                'Content-Type':'application/json;'
            },
        }).then(res => {
         /*   console.log(res)
            console.log('进货成功')*/
        })
    }

}
//motation 同步改变 store
const mutations = {
    addData(state,obj){
        state.xhpData=[]
        state.xhpData.push(...obj)//这里将add 得到的数据添加到数组里面。当前页的数据。
    },
    updata(state,obj){
        state.xhpData.push(obj)//这里将add 得到的数据添加到数组里面。当前页的数据。
    },
    xhpadd(state,obj){
       /* console.log(123);
        console.log(obj);
        console.log(state.xhpData);
        state.xhpData.push(obj)//这里执行报错！！//不用拓展运算符即可
        console.log(state.xhpData);
        //console.log(xhpData)
        //console.log(xhpadd)
        //这里将add 得到的数据添加到数组里面。当前页的数据。*/
    },

}

const getters={
}
export default {
    state,
    actions,
    mutations,
    getters
}